package LuoGu;

import java.util.Scanner;

public class P1157Other {
    static int n,r,w[];
    static boolean box[];

    public static void dfs(int i){
        if(i>r){
            for (int j = 1; j <= r; j++) {
                System.out.printf("%3d",w[j]);
            }
            System.out.println();
            return;
        }
        for(int h=1;h<=n;h++){
            if(box[h]){
                continue;
            }
            if(i>1&&w[i-1]>h){
                continue;
            }
            w[i]=h;
            box[h]=true;
            dfs(i+1);
            box[h]=false;
        }
    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        r=sc.nextInt();
        w=new int[r+1];
        box=new boolean[n+1];
        dfs(1);

    }

}
